﻿using Common;
using gregn6Lib;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem.HandoverSlip
{
    public partial class HandoverPrints : Form
    {
        private GridppReport Report = new GridppReport();
        NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        PatientInfo PatientInfo;
        string Id = string.Empty;
        Tb_User LoginUser;
        ElectronicSignature es;
        /// <summary>
        /// 多张打印 支持单张
        /// </summary>
        /// <param name="loginUser">登录信息</param>
        /// <param name="patientInfo">患者信息</param>
        /// <param name="id">若需要单张打印 请指定id 否则string.Empty </param>
        public HandoverPrints(Tb_User loginUser, PatientInfo patientInfo, string id)
        {
            InitializeComponent();
            this.Id = id;
            PatientInfo = patientInfo;
            LoginUser = loginUser;
            es = new ElectronicSignature(this.LoginUser);
            Report.LoadFromFile(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\手术患者交接单.grf");
            Report.ConnectionString = Utility.GetDatabaseConnectionString();
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);
            axGRPrintViewer1.Report = Report;
        }

        private void ReportFetchRecord()
        {
            var ret = formService.GetNursingFormRecord(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.PatientHandover);
            DataTable dt = new DataTable();
            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                if (!string.IsNullOrEmpty(this.Id))
                    list = list.Where(p => p.Id.Equals(Convert.ToInt32(this.Id))).ToList();
                CreateDataTableHead(dt, list);
                for (int i = 0; i < list.Count; i++)
                {
                    NursingFormRecord record1 = list[i];
                    PatientHandover ps = XmlUtil.XMLToObject<PatientHandover>(record1.NursingFormData, Encoding.UTF8);
                    string image1 = "";
                    string HS = ps.RuShouShuShi.HuShiQianMing;
                    if (!string.IsNullOrEmpty(HS))
                    {
                        image1 = es.GetElectricSignBase64(record1.AreaId, ps.RuShouShuShi.HuShiQianMing);
                    }
                    string image2 = "";
                    string SSSHS = ps.RuShouShuShi.ShouShuShiHuShiQianMing;
                    if (!string.IsNullOrEmpty(SSSHS))
                    {
                        image2 = es.GetElectricSignBase64(record1.AreaId, ps.RuShouShuShi.ShouShuShiHuShiQianMing);
                    }
                    string image3 = "";
                    string CSSSHS = ps.ChuShouShuShi.ShouShuShiHuShiQianMing;
                    if (!string.IsNullOrEmpty(CSSSHS))
                    {
                        image3 = es.GetElectricSignBase64(record1.AreaId, ps.ChuShouShuShi.ShouShuShiHuShiQianMing);
                    }
                    string image4 = "";
                    string CHS = ps.ChuShouShuShi.HuShiQianMing;
                    if (!string.IsNullOrEmpty(CHS))
                    {
                        image4 = es.GetElectricSignBase64(record1.AreaId, ps.ChuShouShuShi.HuShiQianMing);
                    }
                    string image5 = "";
                    string PACUYS = ps.ChuPACU.PACU_YiShiQianMing;
                    if (!string.IsNullOrEmpty(PACUYS))
                    {
                        image5 = es.GetElectricSignBase64(record1.AreaId, ps.ChuPACU.PACU_YiShiQianMing);
                    }
                    string image6 = "";
                    string PACUHS = ps.ChuPACU.HuShiQianMing;
                    if (!string.IsNullOrEmpty(PACUHS))
                    {
                        image6 = es.GetElectricSignBase64(record1.AreaId, ps.ChuPACU.HuShiQianMing);
                    }

                    //根据是否勾选 则是否显示 血制品的下划线
                    if (Report.ControlByName("Line28") != null)
                    {
                        bool line28_visible = ChkStr(ps.RuShouShuShi.XieDaiWuPin, 5) && ps.RuShouShuShi.XieDaiWuPin.Substring(6, 1).Equals("1");
                        Report.ControlByName("Line28").AsLine.Visible = line28_visible;
                    }

                    dt.Rows.Add(
                        ps.RiQi,
                        ps.ShuQianZhenDuan,
                        ps.NiShouShuMingCheng,
                        string.IsNullOrEmpty(ps.JieRuShiShouShuMingCheng) ? string.Empty : ps.JieRuShiShouShuMingCheng,
                        ps.RuShouShuShi.YiShi.Equals("0") ? 1 : 0,
                        ps.RuShouShuShi.YiShi.Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.YiShi.Equals("2") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.TeShuGanRan, 5) && ps.RuShouShuShi.TeShuGanRan.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.TeShuGanRan, 5) && ps.RuShouShuShi.TeShuGanRan.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.TeShuGanRan, 5) && ps.RuShouShuShi.TeShuGanRan.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.TeShuGanRan, 5) && ps.RuShouShuShi.TeShuGanRan.Substring(6, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.TeShuGanRan, 5) && ps.RuShouShuShi.TeShuGanRan.Substring(8, 1).Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.TiWen,
                        ps.RuShouShuShi.MaiBo,
                        ps.RuShouShuShi.HuXi,
                        ps.RuShouShuShi.XueYa.Split('/')[0],
                        ps.RuShouShuShi.XueYa.Split('/')[1],
                        ps.RuShouShuShi.WanDai.Equals("0") ? 1 : 0,
                        ps.RuShouShuShi.WanDai.Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.ShouShuBuWeiBiaoShi.Equals("0") ? 1 : 0,
                         ps.RuShouShuShi.ShouShuBuWeiBiaoShi.Equals("1") ? 1 : 0,
                         ps.RuShouShuShi.BeiPi.Equals("0") ? 1 : 0,
                         ps.RuShouShuShi.BeiPi.Equals("1") ? 1 : 0,
                         ps.RuShouShuShi.GenYi.Equals("0") ? 1 : 0,
                         ps.RuShouShuShi.GenYi.Equals("1") ? 1 : 0,
                         ps.RuShouShuShi.XinZangQiBoQi.Equals("0") ? 1 : 0,
                         ps.RuShouShuShi.XinZangQiBoQi.Equals("1") ? 1 : 0,
                         ps.RuShouShuShi.ZhiRuWu.Equals("0") ? 1 : 0,
                         ps.RuShouShuShi.ZhiRuWu.Equals("1") ? 1 : 0,
                         ps.RuShouShuShi.YiChi.Equals("0") ? 1 : 0,
                         ps.RuShouShuShi.YiChi.Equals("1") ? 1 : 0,
                         ps.RuShouShuShi.YiChi.Equals("2") ? 1 : 0,
                         ps.RuShouShuShi.SuiShenShiWu.Equals("0") ? 1 : 0,
                         ps.RuShouShuShi.SuiShenShiWu.Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.SSSW_MingCheng,
                        ps.RuShouShuShi.SSSW_JianShu,
                        ChkStr(ps.RuShouShuShi.XieDaiWuPin, 5) && ps.RuShouShuShi.XieDaiWuPin.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.XieDaiWuPin, 5) && ps.RuShouShuShi.XieDaiWuPin.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.XieDaiWuPin, 5) && ps.RuShouShuShi.XieDaiWuPin.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.XieDaiWuPin, 5) && ps.RuShouShuShi.XieDaiWuPin.Substring(6, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.XieDaiWuPin, 5) && ps.RuShouShuShi.XieDaiWuPin.Substring(8, 1).Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.XDWP_QiTa,
                        !string.IsNullOrEmpty( ps.RuShouShuShi.XDWP_YaoWu_YiZhiXing)&& ps.RuShouShuShi.XDWP_YaoWu_YiZhiXing.Equals("1")?1:0,
                        ps.RuShouShuShi.XDWP_YaoWu_ZhiXingShiJian,
                        ps.RuShouShuShi.YaoWuGuoMinShi.Equals("0") ? 1 : 0,
                        ps.RuShouShuShi.YaoWuGuoMinShi.Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.YWGMS_QiTa,
                        ChkStr(ps.RuShouShuShi.JingMaiTongLu, 5) && ps.RuShouShuShi.JingMaiTongLu.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.JingMaiTongLu, 5) && ps.RuShouShuShi.JingMaiTongLu.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.JingMaiTongLu, 5) && ps.RuShouShuShi.JingMaiTongLu.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.JingMaiTongLu, 5) && ps.RuShouShuShi.JingMaiTongLu.Substring(6, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.JingMaiTongLu, 5) && ps.RuShouShuShi.JingMaiTongLu.Substring(8, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.ShuQianLiuZhi, 4) && ps.RuShouShuShi.ShuQianLiuZhi.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.ShuQianLiuZhi, 4) && ps.RuShouShuShi.ShuQianLiuZhi.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.ShuQianLiuZhi, 4) && ps.RuShouShuShi.ShuQianLiuZhi.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.ShuQianLiuZhi, 4) && ps.RuShouShuShi.ShuQianLiuZhi.Substring(6, 1).Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.SQLZ_MingCheng,
                        ChkStr(ps.RuShouShuShi.PiFuQingKuang, 3) && ps.RuShouShuShi.PiFuQingKuang.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.PiFuQingKuang, 3) && ps.RuShouShuShi.PiFuQingKuang.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.RuShouShuShi.PiFuQingKuang, 3) && ps.RuShouShuShi.PiFuQingKuang.Substring(4, 1).Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.PFQK_NeiRong,
                        ps.RuShouShuShi.HuanZheQuXiang.Equals("0") ? 1 : 0,
                        ps.RuShouShuShi.HuanZheQuXiang.Equals("1") ? 1 : 0,
                        ps.RuShouShuShi.HuanZheQuXiang.Equals("2") ? 1 : 0,
                        !Base.ESSwitch.Equals("on") ? ps.RuShouShuShi.HuShiQianMing : "",
                        !Base.ESSwitch.Equals("on") ? ps.RuShouShuShi.ShouShuShiHuShiQianMing : "",
                        ps.RuShouShuShi.JieBingRenShiJian,
                        ps.RuShouShuShi.XDWP_BingLi,
                        ps.RuShouShuShi.XDWP_YingXiangZiLiao,
                        ps.RuShouShuShi.XDWP_YaoWu,
                        ps.RuShouShuShi.XDWP_XueZhiPin,

                        ps.ChuShouShuShi.YiShi.Equals("0") ? 1 : 0,
                        ps.ChuShouShuShi.YiShi.Equals("1") ? 1 : 0,
                        ps.ChuShouShuShi.YiShi.Equals("2") ? 1 : 0,
                        ps.ChuShouShuShi.YiShi.Equals("3") ? 1 : 0,

                        ps.ChuShouShuShi.WanDai.Equals("0") ? 1 : 0,
                        ps.ChuShouShuShi.WanDai.Equals("1") ? 0 : 1,
                        ChkStr(ps.ChuShouShuShi.XieDaiWuPin, 4) && ps.ChuShouShuShi.XieDaiWuPin.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.XieDaiWuPin, 4) && ps.ChuShouShuShi.XieDaiWuPin.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.XieDaiWuPin, 4) && ps.ChuShouShuShi.XieDaiWuPin.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.XieDaiWuPin, 4) && ps.ChuShouShuShi.XieDaiWuPin.Substring(6, 1).Equals("1") ? 1 : 0,
                        ps.ChuShouShuShi.XDWP_QiTa,
                        ps.ChuShouShuShi.SuiShenShiWu.Equals("0") ? 1 : 0,
                        ps.ChuShouShuShi.SuiShenShiWu.Equals("1") ? 1 : 0,
                        ps.ChuShouShuShi.SSSW_MingCheng,
                        ps.ChuShouShuShi.SSSW_JianShu,
                        ps.ChuShouShuShi.XueZhiPin.Equals("0") ? 1 : 0,
                        ps.ChuShouShuShi.XueZhiPin.Equals("1") ? 1 : 0,
                        ps.ChuShouShuShi.XZP_MingChengDaiShu,
                        ChkStr(ps.ChuShouShuShi.JingMaiTongLu, 5) && ps.ChuShouShuShi.JingMaiTongLu.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.JingMaiTongLu, 5) && ps.ChuShouShuShi.JingMaiTongLu.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.JingMaiTongLu, 5) && ps.ChuShouShuShi.JingMaiTongLu.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.JingMaiTongLu, 5) && ps.ChuShouShuShi.JingMaiTongLu.Substring(6, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.JingMaiTongLu, 5) && ps.ChuShouShuShi.JingMaiTongLu.Substring(8, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.ShuHouLiuZhi, 5) && ps.ChuShouShuShi.ShuHouLiuZhi.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.ShuHouLiuZhi, 5) && ps.ChuShouShuShi.ShuHouLiuZhi.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.ShuHouLiuZhi, 5) && ps.ChuShouShuShi.ShuHouLiuZhi.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.ShuHouLiuZhi, 5) && ps.ChuShouShuShi.ShuHouLiuZhi.Substring(6, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.ShuHouLiuZhi, 5) && ps.ChuShouShuShi.ShuHouLiuZhi.Substring(8, 1).Equals("1") ? 1 : 0,
                        ps.ChuShouShuShi.SHLZ_QiTa,
                         ChkStr(ps.ChuShouShuShi.PiFuQingKuang, 3) && ps.ChuShouShuShi.PiFuQingKuang.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.PiFuQingKuang, 3) && ps.ChuShouShuShi.PiFuQingKuang.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuShouShuShi.PiFuQingKuang, 3) && ps.ChuShouShuShi.PiFuQingKuang.Substring(4, 1).Equals("1") ? 1 : 0,
                        ps.ChuShouShuShi.PFQK_NeiRong,
                        ps.ChuShouShuShi.HuanZheQuXiang.Equals("0") ? 1 : 0,
                        ps.ChuShouShuShi.HuanZheQuXiang.Equals("1") ? 1 : 0,
                        ps.ChuShouShuShi.HuanZheQuXiang.Equals("2") ? 1 : 0,
                        !Base.ESSwitch.Equals("on") ? ps.ChuShouShuShi.ShouShuShiHuShiQianMing : "",
                        !Base.ESSwitch.Equals("on") ? ps.ChuShouShuShi.HuShiQianMing : "",
                        ps.ChuShouShuShi.ChuShouShuShiShiJian,

                        ps.ChuPACU.YiShi.Equals("0") ? 1 : 0,
                        ps.ChuPACU.YiShi.Equals("1") ? 1 : 0,
                        ps.ChuPACU.YiShi.Equals("2") ? 1 : 0,
                        ps.ChuPACU.YiShi.Equals("3") ? 1 : 0,
                        ps.ChuPACU.MaiBo,
                        ps.ChuPACU.XueYa.Split('/')[0],
                        ps.ChuPACU.XueYa.Split('/')[1],
                        ps.ChuPACU.XueYangBaoHeDu,
                         ps.ChuPACU.WanDai.Equals("0") ? 1 : 0,
                         ps.ChuPACU.WanDai.Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.XieDaiWuPin, 4) && ps.ChuPACU.XieDaiWuPin.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.XieDaiWuPin, 4) && ps.ChuPACU.XieDaiWuPin.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.XieDaiWuPin, 4) && ps.ChuPACU.XieDaiWuPin.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.XieDaiWuPin, 4) && ps.ChuPACU.XieDaiWuPin.Substring(6, 1).Equals("1") ? 1 : 0,
                        ps.ChuPACU.XDWP_QiTa,
                         ps.ChuPACU.SuiShenShiWu.Equals("0") ? 1 : 0,
                         ps.ChuPACU.SuiShenShiWu.Equals("1") ? 1 : 0,
                        ps.ChuPACU.SSSW_MingCheng,
                        ps.ChuPACU.SSSW_JianShu,
                         ps.ChuPACU.XueZhiPin.Equals("0") ? 1 : 0,
                         ps.ChuPACU.XueZhiPin.Equals("1") ? 1 : 0,
                        ps.ChuPACU.XZP_MingChengDaiShu,
                        ChkStr(ps.ChuPACU.JingMaiTongLu, 5) && ps.ChuPACU.JingMaiTongLu.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.JingMaiTongLu, 5) && ps.ChuPACU.JingMaiTongLu.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.JingMaiTongLu, 5) && ps.ChuPACU.JingMaiTongLu.Substring(4, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.JingMaiTongLu, 5) && ps.ChuPACU.JingMaiTongLu.Substring(6, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.JingMaiTongLu, 5) && ps.ChuPACU.JingMaiTongLu.Substring(8, 1).Equals("1") ? 1 : 0,
                         ps.ChuPACU.PCA_Beng.Equals("0") ? 1 : 0,
                         ps.ChuPACU.PCA_Beng.Equals("1") ? 1 : 0,
                         ps.ChuPACU.PCA_BengTuJing.Equals("0") ? 1 : 0,
                         ps.ChuPACU.PCA_BengTuJing.Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.ShuHouLiuZhi, 3) && ps.ChuPACU.ShuHouLiuZhi.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.ShuHouLiuZhi, 3) && ps.ChuPACU.ShuHouLiuZhi.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.ShuHouLiuZhi, 3) && ps.ChuPACU.ShuHouLiuZhi.Substring(4, 1).Equals("1") ? 1 : 0,
                        ps.ChuPACU.SHLZ_NeiRong,
                        ChkStr(ps.ChuPACU.PiFuQingKuang, 3) && ps.ChuPACU.PiFuQingKuang.Substring(0, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.PiFuQingKuang, 3) && ps.ChuPACU.PiFuQingKuang.Substring(2, 1).Equals("1") ? 1 : 0,
                        ChkStr(ps.ChuPACU.PiFuQingKuang, 3) && ps.ChuPACU.PiFuQingKuang.Substring(4, 1).Equals("1") ? 1 : 0,
                        ps.ChuPACU.PFQK_NeiRong,
                         ps.ChuPACU.HuanZheQuXiang.Equals("0") ? 1 : 0,
                         ps.ChuPACU.HuanZheQuXiang.Equals("1") ? 1 : 0,
                         !Base.ESSwitch.Equals("on") ? ps.ChuPACU.PACU_YiShiQianMing : "",
                       !Base.ESSwitch.Equals("on") ? ps.ChuPACU.HuShiQianMing : "",
                        ps.ChuPACU.ChuPACU_ShiJian,
                        record1.PatientName,
                        PatientInfo.SEX,//SEX
                        PatientInfo.AGE,//AGE
                        PatientInfo.NURSE_CELL_NAME,//NURSE_CELL_NAME,
                        PatientInfo.DEPARTMENT_NAME,//DEPARTMENT_NAME
                        PatientInfo.BED_NO,//BED_NO,
                        PatientInfo.PATIENT_ID//PATIENT_ID
                        );
                    //判断列是否存在并赋值
                    if (image1 != "" && dt.Columns.Contains("ElectricSignBase641"))
                    {
                        dt.Rows[0]["ElectricSignBase641"] = image1;
                    }
                    if (image2 != "" && dt.Columns.Contains("ElectricSignBase642"))
                    {
                        dt.Rows[0]["ElectricSignBase642"] = image2;
                    }

                    if (image3 != "" && dt.Columns.Contains("ElectricSignBase643"))
                    {
                        dt.Rows[0]["ElectricSignBase643"] = image3;
                    }

                    if (image4 != "" && dt.Columns.Contains("ElectricSignBase644"))
                    {
                        dt.Rows[0]["ElectricSignBase644"] = image4;
                    }
                    if (image5 != "" && dt.Columns.Contains("ElectricSignBase645"))
                    {
                        dt.Rows[0]["ElectricSignBase645"] = image5;
                    }
                    if (image6 != "" && dt.Columns.Contains("ElectricSignBase646"))
                    {
                        dt.Rows[0]["ElectricSignBase646"] = image6;
                    }

                }
                Utility.FillRecordToReport(Report, dt);
            }
            else if (ret.Code == 2)
            {
                CreateDataTableHead(dt, null);
                DataRow dr = dt.NewRow();
                dt.Rows.Add(dr);
                Utility.FillRecordToReport(Report, dt);
            }
            else if (ret.Code == 0)
            {
                MessageBox.Show(ret.M);
            }
        }

        private void CreateDataTableHead(DataTable dt, List<NursingFormRecord> list)
        {
            dt.Columns.Add("RiQi", typeof(string));
            dt.Columns.Add("SQZD", typeof(string));
            dt.Columns.Add("NSSMC", typeof(string));
            dt.Columns.Add("JRSSSMC", typeof(string));
            dt.Columns.Add("Ru_YiShi1", typeof(string));
            dt.Columns.Add("Ru_YiShi2", typeof(string));
            dt.Columns.Add("Ru_YiShi3", typeof(string));
            dt.Columns.Add("Ru_TSGR1", typeof(string));
            dt.Columns.Add("Ru_TSGR2", typeof(string));
            dt.Columns.Add("Ru_TSGR3", typeof(string));
            dt.Columns.Add("Ru_TSGR4", typeof(string));
            dt.Columns.Add("Ru_TSGR5", typeof(string));
            dt.Columns.Add("Ru_TiWen", typeof(string));
            dt.Columns.Add("Ru_MaiBo", typeof(string));
            dt.Columns.Add("Ru_HuXi", typeof(string));
            dt.Columns.Add("Ru_XueYa1", typeof(string));
            dt.Columns.Add("Ru_XueYa2", typeof(string));
            dt.Columns.Add("Ru_WanDai1", typeof(string));
            dt.Columns.Add("Ru_WanDai2", typeof(string));
            dt.Columns.Add("Ru_SSBWBS1", typeof(string));
            dt.Columns.Add("Ru_SSBWBS2", typeof(string));
            dt.Columns.Add("Ru_BeiPi1", typeof(string));
            dt.Columns.Add("Ru_BeiPi2", typeof(string));
            dt.Columns.Add("Ru_GengYi1", typeof(string));
            dt.Columns.Add("Ru_GengYi2", typeof(string));
            dt.Columns.Add("Ru_XZQBQ1", typeof(string));
            dt.Columns.Add("Ru_XZQBQ2", typeof(string));
            dt.Columns.Add("Ru_ZhiRuWu1", typeof(string));
            dt.Columns.Add("Ru_ZhiRuWu2", typeof(string));
            dt.Columns.Add("Ru_YiChi1", typeof(string));
            dt.Columns.Add("Ru_YiChi2", typeof(string));
            dt.Columns.Add("Ru_YiChi3", typeof(string));
            dt.Columns.Add("Ru_SSSW1", typeof(string));
            dt.Columns.Add("Ru_SSSW2", typeof(string));
            dt.Columns.Add("Ru_SSSWMC", typeof(string));
            dt.Columns.Add("Ru_SSSWJS", typeof(string));
            dt.Columns.Add("Ru_XDWP1", typeof(string));
            dt.Columns.Add("Ru_XDWP2", typeof(string));
            dt.Columns.Add("Ru_XDWP3", typeof(string));
            dt.Columns.Add("Ru_XDWP4", typeof(string));
            dt.Columns.Add("Ru_XDWP5", typeof(string));
            dt.Columns.Add("Ru_XDWPMC", typeof(string));
            dt.Columns.Add("Ru_XDWP_YaoWu_YiZhiXing", typeof(string));
            dt.Columns.Add("Ru_XDWP_YaoWuZhiXingShiJian", typeof(string));
            dt.Columns.Add("Ru_YWGMS1", typeof(string));
            dt.Columns.Add("Ru_YWGMS2", typeof(string));
            dt.Columns.Add("Ru_YWGMSMC", typeof(string));
            dt.Columns.Add("Ru_JMTL1", typeof(string));
            dt.Columns.Add("Ru_JMTL2", typeof(string));
            dt.Columns.Add("Ru_JMTL3", typeof(string));
            dt.Columns.Add("Ru_JMTL4", typeof(string));
            dt.Columns.Add("Ru_JMTL5", typeof(string));
            dt.Columns.Add("Ru_SQLZ1", typeof(string));
            dt.Columns.Add("Ru_SQLZ2", typeof(string));
            dt.Columns.Add("Ru_SQLZ3", typeof(string));
            dt.Columns.Add("Ru_SQLZ4", typeof(string));
            dt.Columns.Add("Ru_SQLZMC", typeof(string));
            dt.Columns.Add("Ru_PFQK1", typeof(string));
            dt.Columns.Add("Ru_PFQK2", typeof(string));
            dt.Columns.Add("Ru_PFQK3", typeof(string));
            dt.Columns.Add("Ru_PFQKMC", typeof(string));
            dt.Columns.Add("Ru_HZQX1", typeof(string));
            dt.Columns.Add("Ru_HZQX2", typeof(string));
            dt.Columns.Add("Ru_HZQX3", typeof(string));
            dt.Columns.Add("Ru_HSQM", typeof(string));
            dt.Columns.Add("Ru_SSSHSQM", typeof(string));
            dt.Columns.Add("Ru_JieBingRenShiJian", typeof(string));

            dt.Columns.Add("Ru_XDWP_BingLiC", typeof(string));
            dt.Columns.Add("Ru_XDWP_YingXiangZiLiao", typeof(string));
            dt.Columns.Add("Ru_XDWP_YaoWu", typeof(string));
            dt.Columns.Add("Ru_XDWP_XueZhiPin", typeof(string));

            dt.Columns.Add("Chu_YiShi1", typeof(string));
            dt.Columns.Add("Chu_YiShi2", typeof(string));
            dt.Columns.Add("Chu_YiShi3", typeof(string));
            dt.Columns.Add("Chu_YiShi4", typeof(string));
            dt.Columns.Add("Chu_WanDai1", typeof(string));
            dt.Columns.Add("Chu_WanDai2", typeof(string));
            dt.Columns.Add("Chu_XDWP1", typeof(string));
            dt.Columns.Add("Chu_XDWP2", typeof(string));
            dt.Columns.Add("Chu_XDWP3", typeof(string));
            dt.Columns.Add("Chu_XDWP4", typeof(string));
            dt.Columns.Add("Chu_XDWPMC", typeof(string));
            dt.Columns.Add("Chu_SSSW1", typeof(string));
            dt.Columns.Add("Chu_SSSW2", typeof(string));
            dt.Columns.Add("Chu_SSSWMC", typeof(string));
            dt.Columns.Add("Chu_SSSWJS", typeof(string));
            dt.Columns.Add("Chu_XueZiPin1", typeof(string));
            dt.Columns.Add("Chu_XueZiPin2", typeof(string));
            dt.Columns.Add("Chu_XueZiPinMC", typeof(string));
            dt.Columns.Add("Chu_JMTL1", typeof(string));
            dt.Columns.Add("Chu_JMTL2", typeof(string));
            dt.Columns.Add("Chu_JMTL3", typeof(string));
            dt.Columns.Add("Chu_JMTL4", typeof(string));
            dt.Columns.Add("Chu_JMTL5", typeof(string));
            dt.Columns.Add("Chu_SHLZ1", typeof(string));
            dt.Columns.Add("Chu_SHLZ2", typeof(string));
            dt.Columns.Add("Chu_SHLZ3", typeof(string));
            dt.Columns.Add("Chu_SHLZ4", typeof(string));
            dt.Columns.Add("Chu_SHLZ5", typeof(string));
            dt.Columns.Add("Chu_SHLZMC", typeof(string));
            dt.Columns.Add("Chu_PFQK1", typeof(string));
            dt.Columns.Add("Chu_PFQK2", typeof(string));
            dt.Columns.Add("Chu_PFQK3", typeof(string));
            dt.Columns.Add("Chu_PFQKMC", typeof(string));
            dt.Columns.Add("Chu_HZQX1", typeof(string));
            dt.Columns.Add("Chu_HZQX2", typeof(string));
            dt.Columns.Add("Chu_HZQX3", typeof(string));
            dt.Columns.Add("Chu_SSSHSQM", typeof(string));
            dt.Columns.Add("Chu_HSQM", typeof(string));
            dt.Columns.Add("Chu_ChuShouShuShiShiJian", typeof(string));

            dt.Columns.Add("PACU_YiShi1", typeof(string));
            dt.Columns.Add("PACU_YiShi2", typeof(string));
            dt.Columns.Add("PACU_YiShi3", typeof(string));
            dt.Columns.Add("PACU_YiShi4", typeof(string));
            dt.Columns.Add("PACU_MaiBo", typeof(string));
            dt.Columns.Add("PACU_XueYa1", typeof(string));
            dt.Columns.Add("PACU_XueYa2", typeof(string));
            dt.Columns.Add("PACU_XYBHD", typeof(string));
            dt.Columns.Add("PACU_WanDai1", typeof(string));
            dt.Columns.Add("PACU_WanDai2", typeof(string));
            dt.Columns.Add("PACU_XDWP1", typeof(string));
            dt.Columns.Add("PACU_XDWP2", typeof(string));
            dt.Columns.Add("PACU_XDWP3", typeof(string));
            dt.Columns.Add("PACU_XDWP4", typeof(string));
            dt.Columns.Add("PACU_XDWPMC", typeof(string));
            dt.Columns.Add("PACU_SSSW1", typeof(string));
            dt.Columns.Add("PACU_SSSW2", typeof(string));
            dt.Columns.Add("PACU_SSSWMC", typeof(string));
            dt.Columns.Add("PACU_SSSWJS", typeof(string));
            dt.Columns.Add("PACU_XueZiPin1", typeof(string));
            dt.Columns.Add("PACU_XueZiPin2", typeof(string));
            dt.Columns.Add("PACU_XueZiPinMC", typeof(string));
            dt.Columns.Add("PACU_JMTL1", typeof(string));
            dt.Columns.Add("PACU_JMTL2", typeof(string));
            dt.Columns.Add("PACU_JMTL3", typeof(string));
            dt.Columns.Add("PACU_JMTL4", typeof(string));
            dt.Columns.Add("PACU_JMTL5", typeof(string));
            dt.Columns.Add("PACU_PCABeng1", typeof(string));
            dt.Columns.Add("PACU_PCABeng2", typeof(string));
            dt.Columns.Add("PACU_PCABengTJ1", typeof(string));
            dt.Columns.Add("PACU_PCABengTJ2", typeof(string));
            dt.Columns.Add("PACU_SHLZ1", typeof(string));
            dt.Columns.Add("PACU_SHLZ2", typeof(string));
            dt.Columns.Add("PACU_SHLZ3", typeof(string));
            dt.Columns.Add("PACU_SHLZMC", typeof(string));
            dt.Columns.Add("PACU_PFQK1", typeof(string));
            dt.Columns.Add("PACU_PFQK2", typeof(string));
            dt.Columns.Add("PACU_PFQK3", typeof(string));
            dt.Columns.Add("PACU_PFQKMC", typeof(string));
            dt.Columns.Add("PACU_HZQX1", typeof(string));
            dt.Columns.Add("PACU_HZQX2", typeof(string));
            dt.Columns.Add("PACU_PACUYSQM", typeof(string));
            dt.Columns.Add("PACU_HSQM", typeof(string));
            dt.Columns.Add("PACU_ChuPACUShiJian", typeof(string));

            dt.Columns.Add("PATIENT_NAME", typeof(string));
            dt.Columns.Add("SEX", typeof(string));
            dt.Columns.Add("AGE", typeof(string));
            dt.Columns.Add("NURSE_CELL_NAME", typeof(string));
            dt.Columns.Add("DEPARTMENT_NAME", typeof(string));
            dt.Columns.Add("BED_NO", typeof(string));
            dt.Columns.Add("PATIENT_ID", typeof(string));
            if (list == null)
                return;
            NursingFormRecord record1 = list[0];
            PatientHandover ps = XmlUtil.XMLToObject<PatientHandover>(record1.NursingFormData, Encoding.UTF8);
            string HS = ps.RuShouShuShi.HuShiQianMing;
            if (!string.IsNullOrEmpty(HS))
            {
                dt.Columns.Add("ElectricSignBase641", typeof(string));
            }
            string SSSHS = ps.RuShouShuShi.ShouShuShiHuShiQianMing;
            if (!string.IsNullOrEmpty(SSSHS))
            {
                dt.Columns.Add("ElectricSignBase642", typeof(string));
            }
            string CSSSHS = ps.ChuShouShuShi.ShouShuShiHuShiQianMing;
            if (!string.IsNullOrEmpty(CSSSHS))
            {
                dt.Columns.Add("ElectricSignBase643", typeof(string));
            }
            string CHS = ps.ChuShouShuShi.HuShiQianMing;
            if (!string.IsNullOrEmpty(CHS))
            {
                dt.Columns.Add("ElectricSignBase644", typeof(string));
            }
            string PACUYS = ps.ChuPACU.PACU_YiShiQianMing;
            if (!string.IsNullOrEmpty(PACUYS))
            {
                dt.Columns.Add("ElectricSignBase645", typeof(string));
            }
            string PACUHS = ps.ChuPACU.HuShiQianMing;
            if (!string.IsNullOrEmpty(PACUHS))
            {
                dt.Columns.Add("ElectricSignBase646", typeof(string));
            }

        }
        /// <summary>
        /// 检查数据项目
        /// </summary>
        /// <param name="str"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        private bool ChkStr(string str, int len)
        {
            if (string.IsNullOrEmpty(str)) return false;
            if (str.IndexOf("#") < 0) return false;
            if (str.Split('#').Length < len) return false;
            return true;
        }
        private void HandoverPrints_Load(object sender, EventArgs e)
        {
            axGRPrintViewer1.Start();
        }
    }
}
